{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "2dfb6ed7-7f81-4d35-95d7-7ff710d11020",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "65"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ord('A')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9160033e-634b-4b6c-aa93-930a7115c219",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "20013"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ord('中')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "95f5b84f-3928-4b72-8783-f7be61f9fb0e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'d'"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chr(100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "241c74e9-f8f4-45d0-8eba-58128a92c92a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'文'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "chr(25991)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0124b8b3-e701-4365-85fa-c075d806d359",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'中'"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'\\u4e2d'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "ee4e1202-e69c-47e7-b82d-251d8520aec2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'ABc'\n"
     ]
    }
   ],
   "source": [
    "x= b'ABc'\n",
    "print(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "19a2dec6-6b5a-4793-baf2-4dfbc79b28a0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "b'\\xe5\\xb0\\x8f\\xe7\\xb1\\xb3'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'小米'.encode('utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "0a1420de-b39e-4920-8309-3fdf3aeb2b13",
   "metadata": {},
   "outputs": [
    {
     "ename": "UnicodeEncodeError",
     "evalue": "'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mUnicodeEncodeError\u001b[0m                        Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[11], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43m小米\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencode\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mascii\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mUnicodeEncodeError\u001b[0m: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)"
     ]
    }
   ],
   "source": [
    "'小米'.encode('ascii')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "b9d1f53c-cea9-483a-8601-7f6a6ed792b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'小米'"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "b'\\xe5\\xb0\\x8f\\xe7\\xb1\\xb3'.decode('utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "ce1dbc41-f86d-419a-9c91-228f9302dc0a",
   "metadata": {},
   "outputs": [
    {
     "ename": "UnicodeDecodeError",
     "evalue": "'utf-8' codec can't decode bytes in position 3-4: invalid continuation byte",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mUnicodeDecodeError\u001b[0m                        Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;124;43mb\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;130;43;01m\\xe5\u001b[39;49;00m\u001b[38;5;130;43;01m\\xb0\u001b[39;49;00m\u001b[38;5;130;43;01m\\x8f\u001b[39;49;00m\u001b[38;5;130;43;01m\\xe7\u001b[39;49;00m\u001b[38;5;130;43;01m\\xb1\u001b[39;49;00m\u001b[38;5;124;43mxx\u001b[39;49m\u001b[38;5;130;43;01m\\xb3\u001b[39;49;00m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mdecode\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mutf-8\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n",
      "\u001b[1;31mUnicodeDecodeError\u001b[0m: 'utf-8' codec can't decode bytes in position 3-4: invalid continuation byte"
     ]
    }
   ],
   "source": [
    "b'\\xe5\\xb0\\x8f\\xe7\\xb1xx\\xb3'.decode('utf-8')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "83599dfc-5488-4c06-a921-03c22b37ae17",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The area of a circle with radius 2.5 is  19.62\n"
     ]
    }
   ],
   "source": [
    "r = 2.5 \n",
    "s = 3.14 * r ** 2 \n",
    "\n",
    "print(f'The area of a circle with radius {r} is {s: .2f}')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "e586a11e-b4ec-4a72-89e9-907a2bc2b03b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "increase 0.180556\n"
     ]
    }
   ],
   "source": [
    "s1 = 72 \n",
    "s2 = 85 \n",
    "r = s2 / s1 -1 \n",
    "print('increase %f' % (r) )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "fbf52ab9-0ec6-48a0-ae1e-0af382f6861a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " 3-01\n"
     ]
    }
   ],
   "source": [
    "print('%2d-%02d' % (3, 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "6e085be0-d020-429a-98ec-c4b4bee1d5bb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'growth rate: 7 %'"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'growth rate: %d %%' % 7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "47e670d0-f9b9-41c0-a443-28f04db0ee45",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
